// pages/my/levelpay/levelpay.js
Page({
  data: {
    bottomHeight: getApp().globalData.bottomHeight,
    userLevel: "",
    level: "",
    levelList: [{
        level: 1,
        title: "小白玩家",
        price: 0.99
      },
      {
        level: 2,
        title: "青铜玩家",
        price: 19.9
      },
      {
        level: 3,
        title: "白银玩家",
        price: 29.9
      },
      {
        level: 4,
        title: "黄金玩家",
        price: 39.9
      },
      {
        level: 5,
        title: "钻石玩家",
        price: 49.9
      },
      {
        level: 6,
        title: "大神玩家",
        price: 59.9
      },
      {
        level: 7,
        title: "荣耀玩家",
        price: 69.9
      },
    ],
    isPayList: false,
    price: 0
  },
  onLoad: function (options) {
    getApp().globalData.http.userLevel().then(res => {
      this.setData({
        userLevel: res.data.level,
        level: options.level,
        price_current: res.data.level == 0 ? 0 : this.data.levelList[res.data.level - 1].price,
        price: this.data.levelList[options.level - 1].price
      });
    });
  },
  levelSel(e) {
    if (e.currentTarget.dataset.level - 1 < this.data.userLevel) return;
    this.setData({
      level: e.currentTarget.dataset.level,
      price: e.currentTarget.dataset.price
    });
  },
  handlePayList() {
    this.setData({
      isPayList: !this.data.isPayList
    });
  },
  pay() {
    getApp().globalData.http.upLevel({
      to: this.data.level
    }).then(res => {
      getApp().globalData.util.pay(res.data, () => {
        wx.navigateBack();
        getCurrentPages()[0].onLoad();
      });
    }).catch(e => {
      getApp().globalData.vant.toast(e.msg);
    });
  }
})